import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from "path"

import path from 'path'
import ElementPlus from 'unplugin-element-plus/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
const pathResolve = (dir: string): any => {  
  return resolve(__dirname, ".", dir)          
}
 
const alias: Record<string, string> = {
  '@': pathResolve("src")
}
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [
        ElementPlusResolver({
          importStyle: 'sass',
        })
      ],
    }),
    Components({
      resolvers: [
        ElementPlusResolver({
          importStyle: 'sass',
      })
    ],
    }),
    ElementPlus({
      useSource: true,
    })
  ],
  server: {
    proxy: {
        '/api': { // 匹配请求路径，
            target: 'http://101.34.50.113:9999', // 代理的目标地址
             // 开发模式，默认的127.0.0.1,开启后代理服务会把origin修改为目标地址
            changeOrigin: true,
            // secure: true, // 是否https接口
            // ws: true, // 是否代理websockets

            // 路径重写，**** 如果你的后端有统一前缀(如:/api)，就不开启；没有就开启
            //简单来说，就是是否改路径 加某些东西
            rewrite: (path) => path.replace(/^\/api/, '') 
        }
    }
  },
  resolve: {
    // ↓路径别名
    alias: {
      '@/': `${path.resolve(__dirname, 'src')}/`,
    },
  },
  css:{
    preprocessorOptions:{
      scss:{
        additionalData:`@use "@/styles/element/index.scss" as *;`,
      }
    }
  }
})
